package com.youle.robots.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.mqtt.core.DefaultMqttPahoClientFactory;
import org.springframework.integration.mqtt.core.MqttPahoClientFactory;

/**
 * Created by IntelliJ IDEA.
 * User: kedong
 * Date: 18-3-22
 * Time: 上午10:36
 * To change this template use File | Settings | File and Code Templates ->Includes->File Header.
 */
@Configuration
public class MqttConfig {

    private final MqttConfigProperties properties;

    public MqttConfig(MqttConfigProperties properties) {
        this.properties = properties;
    }

    @Bean
    public MqttPahoClientFactory mqttClientFactory() {
        DefaultMqttPahoClientFactory factory = new DefaultMqttPahoClientFactory();
        factory.setServerURIs(properties.getUrls());
        factory.setUserName(properties.getUsername());
        factory.setPassword(properties.getPassword());
        factory.setCleanSession(properties.getCleanSession());
        return factory;
    }

}
